<template>

  <!--
   单选:
      type: 'radio'
      data:         绑定数据
      keyName:      绑定key，默认‘key’
      labelName:    绑定label，默认‘label’
      dict:         字典
      binding:      执行data: ()=>{} 返回参数的绑定路径
      disabled:     是否禁用，默认false
  -->
  <el-radio-group
    v-model="currentData"
    :disabled="booleanFun(disabled)"
    size="mini"
  >
    <el-radio
      v-for="item in itemsData"
      :key="item[keyName]"
      :label="item[keyName]"
    >
      {{ item[labelName] }}
    </el-radio>
  </el-radio-group>

</template>

<script>
import {booleanFun, currentData, geItemsData} from '@/components/FlyElement/common'

export default {
  name: 'ARadio',
  props: {
    prop: {
      type: String,
      required: true
    },
    label: {
      type: String,
      required: true
    },
    data: {
      type: String | Number
    },
    keyName: {
      type: String,
      default: 'key'
    },
    labelName: {
      type: String,
      default: 'label'
    },
    dict: {
      type: String
    },
    option: {
      type: Array | Function
    },
    binding: {
      type: String
    },
    disabled: {
      type: Boolean
    }
  },
  data() {
    return {
      itemsData: []
    }
  },
  computed: {
    currentData
  },
  created() {
    this.setItemData()
  },
  methods: {
    booleanFun,
    geItemsData,
    async setItemData() {
      this.itemsData = await this.geItemsData(this.dict, this.option, this.binding)
    }
  }
}
</script>
